package com.bojin.studio.ubattery;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceChangeListener;

public class tabSetting extends PreferenceActivity implements OnPreferenceChangeListener{
    /** Called when the activity is first created. */
	CheckBoxPreference updateSwitchCheckPref;  
	SharedPreferences sharedPreferences;
	
	@Override
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(tabSetting.this);
        updateSwitchCheckPref = (CheckBoxPreference)findPreference("parent_checkbox_preference");  
        updateSwitchCheckPref.setOnPreferenceChangeListener(this); 
     }
	
	@Override  
    public boolean onPreferenceChange(Preference preference, Object newValue) {  
        // TODO Auto-generated method stub  
        
        if(preference.getKey().equals("parent_checkbox_preference"))  
        {  
        	if(sharedPreferences.getBoolean("parent_checkbox_preference", false))
        	{
        		stopService(new Intent(tabSetting.this,NotifyingService.class));	
        	}
        	else
        	{
        		startService(new Intent(tabSetting.this,NotifyingService.class));
        	}
        }  
        else  
        {  
           
            return false;  
        }  
       
        return true;  
    }  
	 
}
